<template>
  <div class="contain-edit">
    <div class="header">
      <p>订单管理/查看详情</p>
      <el-button class="link" type="primary">
        <router-link to="/orderList" style="color: #fff;">返回</router-link>
      </el-button>
    </div>
    <div class="main">
      <div class="list">
        <div class="title">房租信息</div>
        <div class="flex-box-container">
          <div class="item flex">
            <div class="item-key">订单编号:</div>
            <div class="item-value">{{ info && info.orderNo ? info.orderNo : ''}}</div>
          </div>
          <div class="item flex">
            <div class="item-key">租客:</div>
            <div class="item-value">{{ info && info.renterName ? info.renterName : ''}}</div>
          </div>
        </div>
        <div class="flex-box-container">
          <div class="item flex">
            <div class="item-key">房源:</div>
            <div class="item-value">
              {{ info && info.rental && info.rental.gardenName ? info.rental.gardenName : ''}} --
              {{ info && info.rental && info.rental.unitName ? info.rental.unitName : ''}} --
              {{ info && info.rental && info.rental.buildName ? info.rental.buildName : ''}} --
              {{ info && info.rental && info.rental.houseRoomNo ? info.rental.houseRoomNo : ''}}
            </div>
          </div>
          <div class="item flex">
            <div class="item-key">联系电话:</div>
            <div class="item-value">{{ info && info.renterMobile ? info.renterMobile : ''}}</div>
          </div>
        </div>
        <div class="flex-box-container">
          <div class="item flex">
            <div class="item-key">订单金额:</div>
            <div class="item-value">{{ info && info.totalFee ? info.totalFee : ''}}</div>
          </div>
          <div class="item flex">
            <div class="item-key">订单类型:</div>
            <div class="item-value">{{ info && info.orderTypeText ? info.orderTypeText : ''}}</div>
          </div>
        </div>
        <div class="flex-box-container">
          <div class="item flex">
            <div class="item-key">订单状态:</div>
            <div class="item-value">{{ info && info.orderStatusText ? info.orderStatusText : ''}}</div>
          </div>
          <div class="item flex">
            <div class="item-key">支付时间:</div>
            <div class="item-value">{{ info && info.gmtCreated ? info.gmtCreated : ''}}</div>
          </div>
        </div>
      </div>
      <div style="height: 30px"></div>
      <div class="list" v-if="type== 'long_rental' || type == 'year_water_rental'">
        <div class="title">费用明细</div>
        <div class="flex-box-container">
          <div class="item flex">
            <div class="item-key">房租:</div>
            <div class="item-value">{{ info && info.rentFee ? info.rentFee : '0'}}</div>
          </div>
          <div class="item flex">
            <div class="item-key">水费:</div>
            <div class="item-value">{{ info && info.waterFee ? info.waterFee : '0'}}</div>
          </div>
        </div>
        <div class="flex-box-container">
          <div class="item flex">
            <div class="item-key">本月水量:</div>
            <div class="item-value">{{ info && info.currentWaterReadout && info.currentWaterReadout.readouts ? info.currentWaterReadout.readouts : '0'}}</div>
          </div>
          <div class="item flex">
            <div class="item-key">上月水量:</div>
          <div class="item-value">{{ info && info.lastWaterReadouts && info.lastWaterReadouts.readouts ? info.lastWaterReadouts.readouts : '0'}}</div>
        </div>
        </div>
        <div class="flex-box-container">
          <div class="item flex">
            <div class="item-key">上月电量:</div>
            <div class="item-value">{{ info && info.lastElectricReadout && info.lastElectricReadout.readouts ? info.lastElectricReadout.readouts : '0'}}</div>
          </div>
          <div class="item flex">
            <div class="item-key">本月电量:</div>
            <div class="item-value">{{ info && info.currentElectricReadout && info.currentElectricReadout.readouts ? info.currentElectricReadout.readouts : '--'}}</div>
          </div>
        </div>
        <div class="flex-box-container">
          <div class="item flex">
            <div class="item-key">电费:</div>
            <div class="item-value">{{ info && info.electricFee ? info.electricFee : '0'}}</div>
          </div>
          <div class="item flex">
            <div class="item-key" style="overflow: hidden;white-space: nowrap;text-overflow: ellipsis">杂费</div>
            <div class="item-value">{{ info && info.otherFee ? info.otherFee : '0'}}</div>
          </div>
        </div>
        <div class="flex-box-container">
          <div class="item flex">
            <div class="item-key">押金:</div>
            <div class="item-value">{{ info && info.despositFee ? info.despositFee : '0'}}</div>
          </div>
          <div class="item flex">
            <div class="item-key"></div>
            <div class="item-value"></div>
          </div>
        </div>
        <div class="flex-box-container">
          <div class="item flex" v-for="(item, index) in meno" :key="index">
            <div class="item-key">{{item.name}}:</div>
            <div class="item-value">{{ item.value}}</div>
          </div>
        </div>
        <!--<div class="flex-box-container">-->
          <!--<div class="item flex">-->
            <!--<div class="item-key">燃气费:</div>-->
            <!--<div class="item-value">{{ info && info.name ? info.name : ''}}</div>-->
          <!--</div>-->
          <!--<div class="item flex">-->
            <!--<div class="item-key">物业费:</div>-->
            <!--<div class="item-value">{{ info && info.name ? info.name : ''}}</div>-->
          <!--</div>-->
        <!--</div>-->
        <!--<div class="flex-box-container">-->
          <!--<div class="item flex">-->
            <!--<div class="item-key">保洁费:</div>-->
            <!--<div class="item-value">{{ info && info.name ? info.name : ''}}</div>-->
          <!--</div>-->
        <!--</div>-->
    </div>

      <div v-if="pub && identify == 0" style="margin-top: 20px;text-align: center">
        <!--<el-button @click="handleConfirm" type="primary" size="medium" v-if="type == 'day_rental'">确认退租</el-button>-->
        <el-button @click="handleClickPub" type="primary" size="medium">发布订单</el-button>
      </div>
    </div>
    <el-dialog
      title="发布订单"
      :visible.sync="dialogVisible1"
      :before-close="handleClose"
    >
      <div>
        <el-form :model="pubParams" :rules="rules" ref="ruleForm" label-width="100px" class="demo-ruleForm">
            <el-form-item label="杂费:" prop="otherFee">
              <el-input v-model.number="pubParams.otherFee" placeholder="请输入杂费"></el-input>
            </el-form-item>
            <el-form-item label="备注说明:" prop="meno" v-if="otherFeeList && otherFeeList.length">
              <ul class="house-allocate" style="list-style: none;padding-left: 0;">
                <li v-for="(item, index) in otherFeeList" :key="index" style="list-style: none;margin-bottom: 20px;">
                    <span style="width: 50px;display: inline-block;">{{item.name}}</span>
                    <el-input v-model="item.value" placeholder="请输入" style="width: 200px;"></el-input>
                </li>
              </ul>
            </el-form-item>
            <el-form-item style="padding-top: 20px;">
              <el-button @click="handleClose">取 消</el-button>
              <el-button type="primary" @click="handleSure('ruleForm')">确 定</el-button>
            </el-form-item>
        </el-form>
      </div>
    </el-dialog>
  </div>
</template>

<script>
  let CONSTANT = require('../../constant/constant.js');
  let common = require("../../common.js");

  export default {
    data() {
      return {
        id:'',
        info: {
          title: "",
          content: "",
        },
        meno: [],
        order: {

        },
        type: "",
        identify: "",
        pub: "",
        pubParams: {
          meno: "",
          otherFee: ""
        },
        rules: {
          otherFee: [
            {required: true, message: '请输入杂费', trigger: 'blur'},
            {type: 'number', message: '杂费必须为数字值'}
          ]
        },
        dialogVisible1: false,
        otherFeeList: []
      }
    },
    mounted() {
      this.id  = this.$router.currentRoute.query.id;
      this.type = this.$router.currentRoute.query.type;
      this.pub = this.$router.currentRoute.query.pub;
      this.identify = sessionStorage.getItem("identify");
      this.getDetail(this.id);
    },
    methods: {
      getDetail(id){
        let url = this.identify == 1 ? CONSTANT.URL.ORDER.DETAIL : CONSTANT.URL.L_ORDER.DETAIL;
        let param = {
          id:id
        };
        common.requestAjax(url,{},param,(res)=>{
          console.log(res)
          this.loading = false;
          this.info = res.data.bussData;
          this.meno = this.info.meno ? JSON.parse(this.info.meno) : []
          if (this.info.rental.rentalOtherfeeitem) {
            this.info.rental.rentalOtherfeeitem.split(";").map( (item, index) => {
              this.otherFeeList.push({
                name: item,
                value: ""
              })
            })
          }
          this.order = this.info.rental;
        })
      },
      handleClickPub() {
        if (this.info.rental.rentalOtherfeeitem) {
          this.dialogVisible1 = true
        } else {
          this.pubParams = {
            meno: "",
            otherFee: 0
          }
          let url = CONSTANT.URL.L_ORDER.PUB,
            params = Object.assign(pubParams, {id: this.id})
          common.requestAjax(url, {}, params, (data) => {
            if (data.status == 200) {
              this.$message({
                type: "success",
                message: data.msg
              })
              this.dialogVisible1 = false
              this.pubParams = {
                meno: "",
                otherFee: ""
              }
              this.$router.push("/orderList")
            }
            if (data.status == 500) {
              this.$message({
                type: "warning",
                message: data.msg
              })
            }
          })
        }
      },
      handleClose() {
        this.dialogVisible1 = false
      },

      handleSure(formName) {
        this.$refs[formName].validate((valid) => {
          if (valid) {
            let url = CONSTANT.URL.L_ORDER.PUB;
            this.pubParams.meno = JSON.stringify(this.otherFeeList)
            let params = Object.assign({id: this.id}, this.pubParams)
            common.requestAjax(url, {}, params, (data) => {
              if (data.status == 200) {
                this.$message({
                  type: "success",
                  message: data.msg
                })
                this.dialogVisible1 = false
                this.pubParams = {
                  meno: "",
                  otherFee: ""
                }
                this.$router.push("/orderList")
              }
              if (data.status == 500) {
                this.$message({
                  type: "warning",
                  message: data.msg
                })
              }
            })

          } else {
            console.log('error submit!!');
            return false;
          }
        });
      },
    },
  }
</script>
<style lang="scss" scoped>
  .item-left {
    float: left;
    width: 120px;
    padding-left: 20px;
    padding-right: 10px;
    // height: 40px;
    line-height: 40px;
    text-align: right;
    border-right: 1px solid #dedede;
  }
  .item-right {
    // height: 40px;
    // line-height: 40px;
    padding-left: 20px;
    float: left;
  }
  .backage {
    height: auto;
    border: 1px solid #dedede;
    border-top: none;
  }
  .analyse{
    margin-left: 151px;
    height:530px;
    padding-top: 20px;
    display: flex;
  }
  .pic{
    width:330px;
    height:530px;
    // background-color:yellowgreen;
    display: inline-block;
    margin-right: 30px;
    padding-left: 20px;
    .avatar-info{
      .avatar{
        width:100px;
        height:100px;
        background-color:#626262;
        margin-top:50px;
        border-radius:50%;
        float:left;
        .avatar-img{
          width: 100%;
          height: 100%;
        }
      }
      .info{
        // float:left;
        // margin-top:50px;
        margin-left:10px;
        padding: 60px 20px;
      }
    }
  }
  .pic-font{
    border-left: 5px solid #999;
    width: 100px;
    height: 40px;
    line-height: 40px;
    // background-color: pink;
    // margin-left: 15px;
    margin-bottom: 15px;
    display: block;
  }
  .wins{
    display: inline-block;
    height: 350px;
    flex: 1;
  }
  .match{
    list-style:none;
    padding-left:20px;
    margin-top:20px;
    .match-item{
      width: 300px;
      height:50px;
      background-color: #eee;
      margin-bottom:30px;
    }
  }
  #chart{
    width:300px;
    height:300px;
  }
  .honor {
    float: left;
    width: 150px;
    height: 150px;
    margin-right: 20px;
    // background-color: yellow;
    .honor-img{
      width: 70px;
      height: 70px;
      padding: 30px 40px 0px 40px;
    }
    .honor-span{
      width: 40px;
      height: 20px;
      border: 1px solid #ccc;
      display: block;
      margin-left: 55px;
    }
    .honor-text{
      display: block;
      text-align: center;
      font-size: 14px;
    }
  }

</style>


